{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Devito_0_SymPy.ipynb",
      "provenance": [],
      "authorship_tag": "ABX9TyM6EJWzw8rziDCZ6FBVHCvI",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/Divyanshu-ISM/Oil-and-Gas-data-analysis/blob/master/Devito_0_SymPy.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9cg891YSj9tB",
        "colab_type": "text"
      },
      "source": [
        "#Chapter 0 - Sympy basics to build for Devito\n",
        "\n",
        "\n",
        "Author - Divyanshu Vyas ( PE | RE | Data Science | ML/AI)\n",
        "\n",
        "Email - dvyas13ad@gmail.com"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "XzL-4wYkUmgJ",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "f58c8ffb-7dec-476e-e8f6-63bd45db5478"
      },
      "source": [
        "!pip install devito"
      ],
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Collecting devito\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/48/e7/27b91684cded2699bef1ca2e5284d45ed4f3cbea20a7592a746e13751b5b/devito-4.2.2-py3-none-any.whl (374kB)\n",
            "\r\u001b[K     |▉                               | 10kB 18.8MB/s eta 0:00:01\r\u001b[K     |█▊                              | 20kB 1.8MB/s eta 0:00:01\r\u001b[K     |██▋                             | 30kB 2.3MB/s eta 0:00:01\r\u001b[K     |███▌                            | 40kB 2.7MB/s eta 0:00:01\r\u001b[K     |████▍                           | 51kB 2.1MB/s eta 0:00:01\r\u001b[K     |█████▎                          | 61kB 2.3MB/s eta 0:00:01\r\u001b[K     |██████▏                         | 71kB 2.6MB/s eta 0:00:01\r\u001b[K     |███████                         | 81kB 2.8MB/s eta 0:00:01\r\u001b[K     |███████▉                        | 92kB 3.0MB/s eta 0:00:01\r\u001b[K     |████████▊                       | 102kB 2.9MB/s eta 0:00:01\r\u001b[K     |█████████▋                      | 112kB 2.9MB/s eta 0:00:01\r\u001b[K     |██████████▌                     | 122kB 2.9MB/s eta 0:00:01\r\u001b[K     |███████████▍                    | 133kB 2.9MB/s eta 0:00:01\r\u001b[K     |████████████▎                   | 143kB 2.9MB/s eta 0:00:01\r\u001b[K     |█████████████▏                  | 153kB 2.9MB/s eta 0:00:01\r\u001b[K     |██████████████                  | 163kB 2.9MB/s eta 0:00:01\r\u001b[K     |██████████████▉                 | 174kB 2.9MB/s eta 0:00:01\r\u001b[K     |███████████████▊                | 184kB 2.9MB/s eta 0:00:01\r\u001b[K     |████████████████▋               | 194kB 2.9MB/s eta 0:00:01\r\u001b[K     |█████████████████▌              | 204kB 2.9MB/s eta 0:00:01\r\u001b[K     |██████████████████▍             | 215kB 2.9MB/s eta 0:00:01\r\u001b[K     |███████████████████▎            | 225kB 2.9MB/s eta 0:00:01\r\u001b[K     |████████████████████▏           | 235kB 2.9MB/s eta 0:00:01\r\u001b[K     |█████████████████████           | 245kB 2.9MB/s eta 0:00:01\r\u001b[K     |█████████████████████▉          | 256kB 2.9MB/s eta 0:00:01\r\u001b[K     |██████████████████████▊         | 266kB 2.9MB/s eta 0:00:01\r\u001b[K     |███████████████████████▋        | 276kB 2.9MB/s eta 0:00:01\r\u001b[K     |████████████████████████▌       | 286kB 2.9MB/s eta 0:00:01\r\u001b[K     |█████████████████████████▍      | 296kB 2.9MB/s eta 0:00:01\r\u001b[K     |██████████████████████████▎     | 307kB 2.9MB/s eta 0:00:01\r\u001b[K     |███████████████████████████▏    | 317kB 2.9MB/s eta 0:00:01\r\u001b[K     |████████████████████████████    | 327kB 2.9MB/s eta 0:00:01\r\u001b[K     |████████████████████████████▉   | 337kB 2.9MB/s eta 0:00:01\r\u001b[K     |█████████████████████████████▊  | 348kB 2.9MB/s eta 0:00:01\r\u001b[K     |██████████████████████████████▋ | 358kB 2.9MB/s eta 0:00:01\r\u001b[K     |███████████████████████████████▌| 368kB 2.9MB/s eta 0:00:01\r\u001b[K     |████████████████████████████████| 378kB 2.9MB/s \n",
            "\u001b[?25hRequirement already satisfied: sympy<1.6 in /usr/local/lib/python3.6/dist-packages (from devito) (1.1.1)\n",
            "Requirement already satisfied: numpy>=1.14 in /usr/local/lib/python3.6/dist-packages (from devito) (1.18.5)\n",
            "Collecting anytree>=2.4.3\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/a8/65/be23d8c3ecd68d40541d49812cd94ed0f3ee37eb88669ca15df0e43daed1/anytree-2.8.0-py2.py3-none-any.whl (41kB)\n",
            "\r\u001b[K     |███████▉                        | 10kB 18.4MB/s eta 0:00:01\r\u001b[K     |███████████████▊                | 20kB 18.6MB/s eta 0:00:01\r\u001b[K     |███████████████████████▋        | 30kB 23.9MB/s eta 0:00:01\r\u001b[K     |███████████████████████████████▍| 40kB 25.1MB/s eta 0:00:01\r\u001b[K     |████████████████████████████████| 51kB 6.1MB/s \n",
            "\u001b[?25hCollecting cached-property\n",
            "  Downloading https://files.pythonhosted.org/packages/3b/86/85c1be2e8db9e13ef9a350aecd6dea292bd612fa288c2f40d035bb750ded/cached_property-1.5.1-py2.py3-none-any.whl\n",
            "Collecting nbval\n",
            "  Downloading https://files.pythonhosted.org/packages/8a/a0/03ca3ca5cc92e60fedf743e045b1d0a66240a69219e3828234bebfb4d08b/nbval-0.9.5-py2.py3-none-any.whl\n",
            "Collecting codepy>=2019.1\n",
            "  Downloading https://files.pythonhosted.org/packages/6c/81/338a4d4145af7857f9b6fdf9b4d53c58c7eb4c1d092ff6c010efdb4dfdf3/codepy-2019.1.tar.gz\n",
            "Collecting distributed>=1.27\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/b2/2f/342f7d4f8ab336650ba33c3a53de247feff1dc26eb327c0f27710ab187f7/distributed-2.21.0-py3-none-any.whl (646kB)\n",
            "\u001b[K     |████████████████████████████████| 655kB 11.7MB/s \n",
            "\u001b[?25hCollecting pytest-cov\n",
            "  Downloading https://files.pythonhosted.org/packages/3d/13/ae3dec587b1cc07fb9f294e52ea9ad140266aea55adb9e12eade3625bd27/pytest_cov-2.10.0-py2.py3-none-any.whl\n",
            "Requirement already satisfied: click in /usr/local/lib/python3.6/dist-packages (from devito) (7.1.2)\n",
            "Requirement already satisfied: scipy in /usr/local/lib/python3.6/dist-packages (from devito) (1.4.1)\n",
            "Collecting pytest-runner\n",
            "  Downloading https://files.pythonhosted.org/packages/16/45/81b5262c0efc08882bdf183b788e6d28e3d684863990996d8b60967d48da/pytest_runner-5.2-py2.py3-none-any.whl\n",
            "Collecting flake8>=2.1.0\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/6c/20/6326a9a0c6f0527612bae748c4c03df5cd69cf06dfb2cf59d85c6e165a6a/flake8-3.8.3-py2.py3-none-any.whl (72kB)\n",
            "\u001b[K     |████████████████████████████████| 81kB 7.0MB/s \n",
            "\u001b[?25hRequirement already satisfied: pip>=9.0.1 in /usr/local/lib/python3.6/dist-packages (from devito) (19.3.1)\n",
            "Collecting cgen>=2020.1\n",
            "  Downloading https://files.pythonhosted.org/packages/63/d2/2184a24fa93a921937d5da5465e33370c314061f722edf6bebda4e17d7d5/cgen-2020.1.tar.gz\n",
            "Collecting pyrevolve>=2.1.3\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/45/ea/d1fc59baffcef892fac5194e7f25ccae5507bd89cca898bb25dff54d9312/pyrevolve-2.2.tar.gz (191kB)\n",
            "\u001b[K     |████████████████████████████████| 194kB 11.6MB/s \n",
            "\u001b[?25hCollecting multidict\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/1a/95/f50352b5366e7d579e8b99631680a9e32e1b22adfa1629a8f23b1d22d5e2/multidict-4.7.6-cp36-cp36m-manylinux1_x86_64.whl (148kB)\n",
            "\u001b[K     |████████████████████████████████| 153kB 16.1MB/s \n",
            "\u001b[?25hCollecting codecov\n",
            "  Downloading https://files.pythonhosted.org/packages/17/78/523b017c794e1765b765cd70a7605b74735c8b811573a753cca5a0024134/codecov-2.1.8-py2.py3-none-any.whl\n",
            "Requirement already satisfied: pytest>=3.6 in /usr/local/lib/python3.6/dist-packages (from devito) (3.6.4)\n",
            "Requirement already satisfied: psutil>=5.1.0 in /usr/local/lib/python3.6/dist-packages (from devito) (5.4.8)\n",
            "Collecting py-cpuinfo\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/f6/f5/8e6e85ce2e9f6e05040cf0d4e26f43a4718bcc4bce988b433276d4b1a5c1/py-cpuinfo-7.0.0.tar.gz (95kB)\n",
            "\u001b[K     |████████████████████████████████| 102kB 8.7MB/s \n",
            "\u001b[?25hRequirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.6/dist-packages (from sympy<1.6->devito) (1.1.0)\n",
            "Requirement already satisfied: six>=1.9.0 in /usr/local/lib/python3.6/dist-packages (from anytree>=2.4.3->devito) (1.15.0)\n",
            "Requirement already satisfied: coverage in /usr/local/lib/python3.6/dist-packages (from nbval->devito) (3.7.1)\n",
            "Requirement already satisfied: jupyter-client in /usr/local/lib/python3.6/dist-packages (from nbval->devito) (5.3.5)\n",
            "Requirement already satisfied: ipykernel in /usr/local/lib/python3.6/dist-packages (from nbval->devito) (4.10.1)\n",
            "Requirement already satisfied: nbformat in /usr/local/lib/python3.6/dist-packages (from nbval->devito) (5.0.7)\n",
            "Collecting pytools>=2015.1.2\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/6c/78/54e6146f65b8c6779634d28f46cad0ad6effe5f3d7614fe9892abd8e0d3c/pytools-2020.3.1.tar.gz (67kB)\n",
            "\u001b[K     |████████████████████████████████| 71kB 7.3MB/s \n",
            "\u001b[?25hCollecting appdirs>=1.4.0\n",
            "  Downloading https://files.pythonhosted.org/packages/3b/00/2344469e2084fb287c2e0b57b72910309874c3245463acd6cf5e3db69324/appdirs-1.4.4-py2.py3-none-any.whl\n",
            "Requirement already satisfied: zict>=0.1.3 in /usr/local/lib/python3.6/dist-packages (from distributed>=1.27->devito) (2.0.0)\n",
            "Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from distributed>=1.27->devito) (49.1.0)\n",
            "Collecting contextvars; python_version < \"3.7\"\n",
            "  Downloading https://files.pythonhosted.org/packages/83/96/55b82d9f13763be9d672622e1b8106c85acb83edd7cc2fa5bc67cd9877e9/contextvars-2.4.tar.gz\n",
            "Requirement already satisfied: tornado>=5; python_version < \"3.8\" in /usr/local/lib/python3.6/dist-packages (from distributed>=1.27->devito) (5.1.1)\n",
            "Collecting cloudpickle>=1.5.0\n",
            "  Downloading https://files.pythonhosted.org/packages/8f/d7/bdb029d3de92c165afe6cdc69a2d01e26189b3bad64a1edf6ef5a5f11d1a/cloudpickle-1.5.0-py3-none-any.whl\n",
            "Requirement already satisfied: tblib>=1.6.0 in /usr/local/lib/python3.6/dist-packages (from distributed>=1.27->devito) (1.6.0)\n",
            "Requirement already satisfied: dask>=2.9.0 in /usr/local/lib/python3.6/dist-packages (from distributed>=1.27->devito) (2.12.0)\n",
            "Requirement already satisfied: sortedcontainers!=2.0.0,!=2.0.1 in /usr/local/lib/python3.6/dist-packages (from distributed>=1.27->devito) (2.2.2)\n",
            "Requirement already satisfied: pyyaml in /usr/local/lib/python3.6/dist-packages (from distributed>=1.27->devito) (3.13)\n",
            "Requirement already satisfied: msgpack>=0.6.0 in /usr/local/lib/python3.6/dist-packages (from distributed>=1.27->devito) (1.0.0)\n",
            "Requirement already satisfied: toolz>=0.8.2 in /usr/local/lib/python3.6/dist-packages (from distributed>=1.27->devito) (0.10.0)\n",
            "Collecting pyflakes<2.3.0,>=2.2.0\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/69/5b/fd01b0c696f2f9a6d2c839883b642493b431f28fa32b29abc465ef675473/pyflakes-2.2.0-py2.py3-none-any.whl (66kB)\n",
            "\u001b[K     |████████████████████████████████| 71kB 7.3MB/s \n",
            "\u001b[?25hCollecting mccabe<0.7.0,>=0.6.0\n",
            "  Downloading https://files.pythonhosted.org/packages/87/89/479dc97e18549e21354893e4ee4ef36db1d237534982482c3681ee6e7b57/mccabe-0.6.1-py2.py3-none-any.whl\n",
            "Collecting pycodestyle<2.7.0,>=2.6.0a1\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/10/5b/88879fb861ab79aef45c7e199cae3ef7af487b5603dcb363517a50602dd7/pycodestyle-2.6.0-py2.py3-none-any.whl (41kB)\n",
            "\u001b[K     |████████████████████████████████| 51kB 6.2MB/s \n",
            "\u001b[?25hRequirement already satisfied: importlib-metadata; python_version < \"3.8\" in /usr/local/lib/python3.6/dist-packages (from flake8>=2.1.0->devito) (1.7.0)\n",
            "Collecting contexttimer\n",
            "  Downloading https://files.pythonhosted.org/packages/1d/e0/504aa08a83dc2ff90f61a83b5f70d689e1f5138ab30576124ea2ff9f5076/contexttimer-0.3.3.tar.gz\n",
            "Requirement already satisfied: requests>=2.7.9 in /usr/local/lib/python3.6/dist-packages (from codecov->devito) (2.23.0)\n",
            "Requirement already satisfied: atomicwrites>=1.0 in /usr/local/lib/python3.6/dist-packages (from pytest>=3.6->devito) (1.4.0)\n",
            "Requirement already satisfied: pluggy<0.8,>=0.5 in /usr/local/lib/python3.6/dist-packages (from pytest>=3.6->devito) (0.7.1)\n",
            "Requirement already satisfied: py>=1.5.0 in /usr/local/lib/python3.6/dist-packages (from pytest>=3.6->devito) (1.9.0)\n",
            "Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.6/dist-packages (from pytest>=3.6->devito) (19.3.0)\n",
            "Requirement already satisfied: more-itertools>=4.0.0 in /usr/local/lib/python3.6/dist-packages (from pytest>=3.6->devito) (8.4.0)\n",
            "Requirement already satisfied: pyzmq>=13 in /usr/local/lib/python3.6/dist-packages (from jupyter-client->nbval->devito) (19.0.1)\n",
            "Requirement already satisfied: traitlets in /usr/local/lib/python3.6/dist-packages (from jupyter-client->nbval->devito) (4.3.3)\n",
            "Requirement already satisfied: jupyter-core>=4.6.0 in /usr/local/lib/python3.6/dist-packages (from jupyter-client->nbval->devito) (4.6.3)\n",
            "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/dist-packages (from jupyter-client->nbval->devito) (2.8.1)\n",
            "Requirement already satisfied: ipython>=4.0.0 in /usr/local/lib/python3.6/dist-packages (from ipykernel->nbval->devito) (5.5.0)\n",
            "Requirement already satisfied: ipython-genutils in /usr/local/lib/python3.6/dist-packages (from nbformat->nbval->devito) (0.2.0)\n",
            "Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in /usr/local/lib/python3.6/dist-packages (from nbformat->nbval->devito) (2.6.0)\n",
            "Requirement already satisfied: decorator>=3.2.0 in /usr/local/lib/python3.6/dist-packages (from pytools>=2015.1.2->codepy>=2019.1->devito) (4.4.2)\n",
            "Requirement already satisfied: heapdict in /usr/local/lib/python3.6/dist-packages (from zict>=0.1.3->distributed>=1.27->devito) (1.0.1)\n",
            "Collecting immutables>=0.9\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/99/e0/ea6fd4697120327d26773b5a84853f897a68e33d3f9376b00a8ff96e4f63/immutables-0.14-cp36-cp36m-manylinux1_x86_64.whl (98kB)\n",
            "\u001b[K     |████████████████████████████████| 102kB 8.5MB/s \n",
            "\u001b[?25hRequirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.6/dist-packages (from importlib-metadata; python_version < \"3.8\"->flake8>=2.1.0->devito) (3.1.0)\n",
            "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests>=2.7.9->codecov->devito) (2.10)\n",
            "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests>=2.7.9->codecov->devito) (3.0.4)\n",
            "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests>=2.7.9->codecov->devito) (2020.6.20)\n",
            "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests>=2.7.9->codecov->devito) (1.24.3)\n",
            "Requirement already satisfied: pickleshare in /usr/local/lib/python3.6/dist-packages (from ipython>=4.0.0->ipykernel->nbval->devito) (0.7.5)\n",
            "Requirement already satisfied: pexpect; sys_platform != \"win32\" in /usr/local/lib/python3.6/dist-packages (from ipython>=4.0.0->ipykernel->nbval->devito) (4.8.0)\n",
            "Requirement already satisfied: prompt-toolkit<2.0.0,>=1.0.4 in /usr/local/lib/python3.6/dist-packages (from ipython>=4.0.0->ipykernel->nbval->devito) (1.0.18)\n",
            "Requirement already satisfied: simplegeneric>0.8 in /usr/local/lib/python3.6/dist-packages (from ipython>=4.0.0->ipykernel->nbval->devito) (0.8.1)\n",
            "Requirement already satisfied: pygments in /usr/local/lib/python3.6/dist-packages (from ipython>=4.0.0->ipykernel->nbval->devito) (2.1.3)\n",
            "Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.6/dist-packages (from pexpect; sys_platform != \"win32\"->ipython>=4.0.0->ipykernel->nbval->devito) (0.6.0)\n",
            "Requirement already satisfied: wcwidth in /usr/local/lib/python3.6/dist-packages (from prompt-toolkit<2.0.0,>=1.0.4->ipython>=4.0.0->ipykernel->nbval->devito) (0.2.5)\n",
            "Building wheels for collected packages: codepy, cgen, pyrevolve, py-cpuinfo, pytools, contextvars, contexttimer\n",
            "  Building wheel for codepy (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Created wheel for codepy: filename=codepy-2019.1-cp36-none-any.whl size=19313 sha256=da5ef751c7380658b6012fbc3831f05b68c5a509ed8ab0f81504844bc27ee390\n",
            "  Stored in directory: /root/.cache/pip/wheels/f4/53/e7/b53cf7ba45381b676bbd5eaaedc19ae82e1c397e9c1766ddf4\n",
            "  Building wheel for cgen (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Created wheel for cgen: filename=cgen-2020.1-cp36-none-any.whl size=15825 sha256=e1a1c7f6ef4a7763fa8b8cae0c57310b93eeb9617f5b285e47b66e573679f9a5\n",
            "  Stored in directory: /root/.cache/pip/wheels/92/c2/1f/9d3d4ff4f49366d164156238a9d3e818cb4d58ab9110ca1d3a\n",
            "  Building wheel for pyrevolve (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Created wheel for pyrevolve: filename=pyrevolve-2.2-cp36-cp36m-linux_x86_64.whl size=248185 sha256=92c60f710d588ea0985de328baf9e60b71e7c7c4dfecce6dbf30ffe9b783ee52\n",
            "  Stored in directory: /root/.cache/pip/wheels/91/59/ff/3aebf19beedd85ed0d7de5b086da754d28e8369a0706fb760d\n",
            "  Building wheel for py-cpuinfo (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Created wheel for py-cpuinfo: filename=py_cpuinfo-7.0.0-cp36-none-any.whl size=20069 sha256=4c1ec7057517d8a6e9672c321d3b1b48cb9d9491f1104e66825a86f992afbe59\n",
            "  Stored in directory: /root/.cache/pip/wheels/f1/93/7b/127daf0c3a5a49feb2fecd468d508067c733fba5192f726ad1\n",
            "  Building wheel for pytools (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Created wheel for pytools: filename=pytools-2020.3.1-py2.py3-none-any.whl size=65243 sha256=455aaa93c3e144b1e2bf90472da00101347ef8fd877894b5719b0c70d756a8e0\n",
            "  Stored in directory: /root/.cache/pip/wheels/ac/01/07/fe484d8aae398b7f6150dae468a53887f0e7e265f1fc7fc975\n",
            "  Building wheel for contextvars (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Created wheel for contextvars: filename=contextvars-2.4-cp36-none-any.whl size=7666 sha256=31879f32afe2d8d56420346d1890f2e278242c3046b13270efddb18421269708\n",
            "  Stored in directory: /root/.cache/pip/wheels/a5/7d/68/1ebae2668bda2228686e3c1cf16f2c2384cea6e9334ad5f6de\n",
            "  Building wheel for contexttimer (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Created wheel for contexttimer: filename=contexttimer-0.3.3-cp36-none-any.whl size=5817 sha256=b67e2f3f3a1971c3a640b6b1afb00e787736125e295cfd7b4e8ea9c54c17f1d2\n",
            "  Stored in directory: /root/.cache/pip/wheels/b3/e2/35/565145ce0127c7451b6503dfabb2b56e9908c863e40c6b1870\n",
            "Successfully built codepy cgen pyrevolve py-cpuinfo pytools contextvars contexttimer\n",
            "\u001b[31mERROR: gym 0.17.2 has requirement cloudpickle<1.4.0,>=1.2.0, but you'll have cloudpickle 1.5.0 which is incompatible.\u001b[0m\n",
            "\u001b[31mERROR: pytest-cov 2.10.0 has requirement coverage>=4.4, but you'll have coverage 3.7.1 which is incompatible.\u001b[0m\n",
            "\u001b[31mERROR: pytest-cov 2.10.0 has requirement pytest>=4.6, but you'll have pytest 3.6.4 which is incompatible.\u001b[0m\n",
            "Installing collected packages: anytree, cached-property, nbval, appdirs, pytools, cgen, codepy, immutables, contextvars, cloudpickle, distributed, pytest-cov, pytest-runner, pyflakes, mccabe, pycodestyle, flake8, contexttimer, pyrevolve, multidict, codecov, py-cpuinfo, devito\n",
            "  Found existing installation: cloudpickle 1.3.0\n",
            "    Uninstalling cloudpickle-1.3.0:\n",
            "      Successfully uninstalled cloudpickle-1.3.0\n",
            "  Found existing installation: distributed 1.25.3\n",
            "    Uninstalling distributed-1.25.3:\n",
            "      Successfully uninstalled distributed-1.25.3\n",
            "Successfully installed anytree-2.8.0 appdirs-1.4.4 cached-property-1.5.1 cgen-2020.1 cloudpickle-1.5.0 codecov-2.1.8 codepy-2019.1 contexttimer-0.3.3 contextvars-2.4 devito-4.2.2 distributed-2.21.0 flake8-3.8.3 immutables-0.14 mccabe-0.6.1 multidict-4.7.6 nbval-0.9.5 py-cpuinfo-7.0.0 pycodestyle-2.6.0 pyflakes-2.2.0 pyrevolve-2.2 pytest-cov-2.10.0 pytest-runner-5.2 pytools-2020.3.1\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.colab-display-data+json": {
              "pip_warning": {
                "packages": [
                  "cloudpickle"
                ]
              }
            }
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "It63-uLGT_ul",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 751
        },
        "outputId": "538c7f91-718e-4158-fa0b-802c7ff11d42"
      },
      "source": [
        "import numpy as np\n",
        "import devito\n",
        "from devito import Grid, Function, Eq, Operator\n",
        "grid = Grid(shape=(21,), extent=(1.0,), origin=(0.0,), dtype=np.float32)\n",
        "x = grid.dimensions[0]\n",
        "f = Function(name='f', grid=grid, space_order=8)\n",
        "g = Function(name='g', grid=grid, space_order=8)\n",
        "eq_dfdx = Eq(g, getattr(f, 'dx')(x+0.5*x.spacing))\n",
        "op = Operator(eq_dfdx)\n",
        "print(op)"
      ],
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "#define _POSIX_C_SOURCE 200809L\n",
            "#include \"stdlib.h\"\n",
            "#include \"math.h\"\n",
            "#include \"sys/time.h\"\n",
            "#include \"xmmintrin.h\"\n",
            "#include \"pmmintrin.h\"\n",
            "\n",
            "struct dataobj\n",
            "{\n",
            "  void *restrict data;\n",
            "  int * size;\n",
            "  int * npsize;\n",
            "  int * dsize;\n",
            "  int * hsize;\n",
            "  int * hofs;\n",
            "  int * oofs;\n",
            "} ;\n",
            "\n",
            "struct profiler\n",
            "{\n",
            "  double section0;\n",
            "} ;\n",
            "\n",
            "\n",
            "int Kernel(struct dataobj *restrict f_vec, struct dataobj *restrict g_vec, const float h_x, struct profiler * timers, const int x_M, const int x_m)\n",
            "{\n",
            "  /* Flush denormal numbers to zero in hardware */\n",
            "  _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);\n",
            "  _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);\n",
            "  struct timeval start_section0, end_section0;\n",
            "  gettimeofday(&start_section0, NULL);\n",
            "  /* Begin section0 */\n",
            "  for (int x = x_m; x <= x_M; x += 1)\n",
            "  {\n",
            "    g[x + 8] = 1.0F + (6.97544643e-4F*(f[x + 5] - f[x + 12]) + 9.5703125e-3F*(-f[x + 6] + f[x + 11]) + 7.97526042e-2F*(f[x + 7] - f[x + 10]) + 1.1962890625F*(-f[x + 8] + f[x + 9]))/h_x;\n",
            "  }\n",
            "  /* End section0 */\n",
            "  gettimeofday(&end_section0, NULL);\n",
            "  timers->section0 += (double)(end_section0.tv_sec-start_section0.tv_sec)+(double)(end_section0.tv_usec-start_section0.tv_usec)/1000000;\n",
            "  return 0;\n",
            "}\n",
            "\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "9vZ53SmkUZ6y",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import numpy as np\n",
        "from sympy import *\n",
        "from devito import *\n",
        "\n",
        "import matplotlib.pyplot as plt\n",
        "%matplotlib inline"
      ],
      "execution_count": 4,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jc7UmJAYVB3H",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "grd = Grid(shape=(4,4),extent=(4,4))"
      ],
      "execution_count": 5,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "iDcIjcttV8A4",
        "colab_type": "text"
      },
      "source": [
        "#Let's Brush up a bit of SymPy first. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "3RKyOCD4VNdD",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import math\n",
        "\n",
        "init_printing(pretty_print=True)\n"
      ],
      "execution_count": 11,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "E2i044n6WEs5",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 51
        },
        "outputId": "94983785-4cdb-4e3b-f483-04c102aabc0f"
      },
      "source": [
        "print(math.sqrt(8))\n",
        "\n",
        "print(sqrt(8))"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "2.8284271247461903\n",
            "2*sqrt(2)\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "tGVt3tNiWKql",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 37
        },
        "outputId": "7a33a672-ad0f-4ca5-c16e-dffe333f4fa1"
      },
      "source": [
        "sqrt(8)"
      ],
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAACwAAAAcCAYAAAAa/l2sAAAABHNCSVQICAgIfAhkiAAAAbpJREFUWIXt1z1oFEEYxvFf4gUUqxjxA0REEAtLWxu1EDGSwlosEiSFBDsrwU4Lg4XgRyOCWAiClQpWFkkXEAkikYCiIGoVQbBI/ChmkL2927tdnQkI94dll9l3nued2Z15dxmQl6F18Pi1Dh7JOIjplILDKcW6cAKPUwrmTng3PqQUzJnwdnxKLZoz4eN4klE/OTdlmJBcMzyCH/iZWriY8Bim8AjL+I6vmMOkZoM7FPt1I5nPtLDJf8R9XMYdrMT2h+oXmisYze1zBCd1jnAH3kexU6V7w2h10bqd2OcPGwrXb/FGZyn9hk04ii94GttHhcc6hJeF+L3YifkKz6Y+bdR9X1bjea3QdgCfMV6KHff31a2bT2NaWBRm5Fjp3j5hwYwU2m5l8GnE1ShSNWtLwmOEzZjN5FOLmSjyGlsqYmZxLV5PCBUuh09fzkWRV8IKruKwsIgIiW/M5NOT81FkEdv6xLaEPXQ/bmT0qeRCFHmBrTX7PMA9nM3s08HFKLKg2bt0Wvhu2JXZp60EnsFd4aPlurBdlXkXY8qM4ZnwS9SPf/Fp45Iw6l7H8x7999RINoXPgAH/Nb8BdoiFOuZT3KEAAAAASUVORK5CYII=\n",
            "text/latex": "$$2 \\sqrt{2}$$",
            "text/plain": [
              "2⋅√2"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 13
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "v3Bc0lmjWbxN",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "x , y = symbols('x y')"
      ],
      "execution_count": 14,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "yDmoyFykX1rz",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "expr = x**2 + 2*x + 1"
      ],
      "execution_count": 16,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "FJ29zhQSX5mO",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 38
        },
        "outputId": "61841a0e-663f-421e-86b9-1542694b000a"
      },
      "source": [
        "expr"
      ],
      "execution_count": 17,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG4AAAAWCAYAAAAhKqlXAAAABHNCSVQICAgIfAhkiAAAAtBJREFUaIHt2E/IVGUUx/GPf2ghCmEptXAjRQRlbgOFyYpAiILc1KYnbOFCpEUiCcKLG1v4pxApN/EGuiiCggrKRQUqCAmKggqKvbRIQfFfUJCULc7z4jjOzH3vnTszZvcLF2ae+5zznN8995577kPD/5L38DNu4BK+xlNjjahhRnyPt0SynsaXuIiF4wyqoTzz8TdeHncg9zuza/a3IPu8WrPfIh7C2+KJP4c/cR2HsFb9OofFGuzGQfH6uYV9o1j4cxzDnFEs1sY6IfI37Mc2fIJrefwLzBpxTFU4LuL9HaeNKHE7xYVbWtE+iUBbFWxXifLc+WQ9gl+z39cqxlWGpLoGeA6Pi5uspU/iOoUe0F3kLEzmc+938bMLr4sLeL5azAPxg+ho/+kYv4iP8+9Wx7mqWofJjzib1y7FM6K5OOXOcrcjO9vbxeZDcYGeLB3mnSSD3a292Jj97uoYr6K1iKQ+DS0lS+VkNkj5/+b8/zN3P6F7xEt0lShL08f8CoEm9SduLk5mvy91OT9p5lpnQjLGxC0RXdkvWJ+Nv8MDXebe6nFMVAg0qT9x27PPb3ucL6N1JiRjTBzRlU0n4TDm1RBIO1N6J73bMVlhjQ3Z9rT+GwJVtU4VxDyohpY+iZvbw+hS2++1+KPkokV8gAc7xpbjFXwqLko7x0v6Xy/evafwPK70mVtV67A1lOYN0Z1dEBn/aNgLZpJ6ysw72c9JLC6YW7fWZEylcjX+wgkswhncxBM1BFJEMrjoTdnHMTxcMHcYWpMxJG6FKBPn8WgeW5ONv6ohkCKSwURvyfZHFW9yD0trMqLETb/jluMbsb/3oigdxFbRUVG3V4o9tHuRN7FVfJcdFI1JJ1OiQbiXtb6aD+KzCp51u7G5jHenJz8mPqCvYlkXZy+IzB8ZQqDtJNXv1gnFXd1Phq81GeyJm9Bfw1RFvw0NDQ0NDf8Z/gX0AwWCb5czSwAAAABJRU5ErkJggg==\n",
            "text/latex": "$$x^{2} + 2 x + 1$$",
            "text/plain": [
              " 2          \n",
              "x  + 2⋅x + 1"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 17
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "KPKbXDefX8wC",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 38
        },
        "outputId": "eaa04954-5b14-419c-bbe4-18158e207f39"
      },
      "source": [
        "expr + y**2"
      ],
      "execution_count": 18,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJwAAAAaCAYAAABCUTWIAAAABHNCSVQICAgIfAhkiAAAA8pJREFUaIHt2kmIHFUcx/FPNHrQiLuooAdRVHCJBwmCgTYqgiCKxoNeLIkEDyEYF1xAGDwYBTUG1yDICHpwQcUFNIga42DQQEKiiaDEQUEjI44biut4eG+cnkr3dHctXW26vlBM11v+9f/969Vbh5qa/xG34yP8hAm8itMq9Wi4GLr4v4lrBZGn4yXsxmFVOjVEDH38F+BvXFK1I0PKwMd/n4LtHRRtThZstxOH4zrhC/8cv+FHvI9litc5qFQVf1iKh7BRGOKn8HTZD30OW7Bv2Q9Kcb0g8Gs8g9V4Ej/E9Bcwr88+VUFV8YetQqx/xk59aHAPCC/8hIz1E8HJRoa6S4RhJN2THY0vo90rMvrVC4nsGvJSZfzhPJwkfNgNbRpc+gWt1/rlzMNozLunxcPW4Crhxe/K6HAe3hZWaP+k0nfj8fi7kcrLqrUsbozPvKlN/sn4He+1yKs6/vAOPhM0dM2ZwqRzh9nd8v3R0LoWddYKL/bUTG7OkCind7gl2l2TSs+itROJ7BoWxbrPt8lfj79wRip9EOPf0MOQOhoLJ/H+jnj/rD17xEeECeISYfiavhZkcDJRfIObj+3R7kUt8kd1r7UbEtk17IdfhSlAmiuj3bWp9EGNf0MPDe44YZX3BVbEim9g/xZlp9pcIxmcTBTf4O6LNl9vk9+L1m5I5NOwIdY/pintQHyFb3Fwqvygxr+hx0XDajPOj+GAApxoZlz7YLW6RjM8Y2Wsu9PcG6FZtY538DmLhrtj2cub0u41uxcugvE2PhYV/4Y2DW5+mwoTTb+XCV19kTyIQ1JpC3EpnhIC0szWHu2vEIafHTgf389RNqvWMjSMxb+L8CJOwSp8EG0WRdnx74mrhdXeN0IrfazMhzWRKKZLvyHa2Y6jOpQtWmsin4ZDoz8b4v1bwsLmrJx+dUOigiH1YvyBbTgSn+JPYUleNon8gm+NNrbgiA5ly9CayK/hE/wifAxTeDSHrV5I9LnBnSsMJ7vMTFqXxoovF+BEJxL5BN8Z62/W+fC6LK2J/C9tnZkd+wmh1+sHiT40uOk53EK8Jpw/XigMMYQjoc3C2L5YOCcbRK7BXcLws1FYMKQZFya/g651DMuFrY1VqjkXzcJl8SJszcA5ZhYc3+FmOFHYOJy056YiXCC01k0lOTpNIvsXNqLzSutd5WtN5O8lFkcbH+rv+W8in+8j5o7/eE7/akriFaGnPrtqR2r2fqYXCg9X7UjN3svxuA1PCIfzHyt+o72m5j+WC73apPD/bMdW605NTU1NTU1NTU3NbP4FFYFrIAjnVCIAAAAASUVORK5CYII=\n",
            "text/latex": "$$x^{2} + 2 x + y^{2} + 1$$",
            "text/plain": [
              " 2          2    \n",
              "x  + 2⋅x + y  + 1"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 18
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "fQE0108IY1Rx",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 38
        },
        "outputId": "e9e1582b-0585-443b-e705-b780b02d78a7"
      },
      "source": [
        "expr+1"
      ],
      "execution_count": 19,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG4AAAAWCAYAAAAhKqlXAAAABHNCSVQICAgIfAhkiAAAAn9JREFUaIHt2MurTVEcwPGPRwai5BUDEymU1x9AySOlZMDIxBIDA8lEopRMGOCSJBNdAwNSFAojdSnlFlEYiJsBSnkNKOIarHVxj/PcZ+9zxP7WrnvWXr/f+n3v3nvttRcl/yW7cRcf8QaXMa+rFZU0xXVsEi/WfFzEa0zsZlElrTMO37Cm24X864zMOd/4lPNdznkbMQlbxCf+KT7jA25hs/w9i6CrDudxD6OKHKQKWzGIlziLAziN96n9AkZ0uKZW6ZrDkTTozIzxQSxwaYbYZeL0XHlXTsOLlHddxrpaIeiSw40aHUagN507WCWuB68wJ0PBQwTZpeuxJ+U9XtGe1bUeQWcdfrJQXFw8Mny6O5wCT1WJOSauJOe2WVxQjPTOlLenoj2LayOCzjoMozd1Cun30NU+58/H+IT4DbdMfKSHjnEZigvylx6NhynvqirnezXv2gxB5x1+MkNc0TzHthRwDWOq9B2scezLUGCQv/ShlPNqjfOtuDZD0HmHYRzw6yLcxtgcC4EBtS96taM3wxjbU+xj9TcEsroONKi5UIfRNQLe/Pb3ZnzKMGg9jmJCRdsirMUZ8Z/yO/dbzL9NfPc+wnK8rdM3q+vf5AA24Lu4ShzEyRYHzEqQzzSzI+V5iKkN+ubtGnTeAazGFzzAFDzBV8xus5BmCNqX3pVy3MPkBn2LcA066wAWi9PEM0xPbetTkkttFNIsQXvSe1N8v8ab3EW5Bh1yGHrHLcIVcW9spTh1ELdZ+sV5ewn6MhZUNBuxX/wu6xNf6pUMiAuEv9W1FQcwS/yAfocFVTqvEO+CO/nW+QdB9rt1n8arupuKdw2KdygpKSkpKfmn+QHG4xCPfaemwgAAAABJRU5ErkJggg==\n",
            "text/latex": "$$x^{2} + 2 x + 2$$",
            "text/plain": [
              " 2          \n",
              "x  + 2⋅x + 2"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 19
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "nUajo83RY3Hs",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 38
        },
        "outputId": "62857d72-9983-4111-ca22-f7849565c3d1"
      },
      "source": [
        "expr - x"
      ],
      "execution_count": 20,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGEAAAAWCAYAAADQIfLaAAAABHNCSVQICAgIfAhkiAAAAh1JREFUaIHt182LTWEcwPHPIAuNkpWNjZekvMwfQF2TUkoUG1ZHLP0DZDE7lNck2V1lQ8rCBhsLKTULsxBJmIVQsxhRrLgWz7mcue41c57zMq653zp1z8vze77n+d3f8zyHAX3PcYzjM6ZwF5vm1WgBch+HhYHfjDv4iJXzKbXQGcZ37JlvkX5iUcnxlqcxp0uO248cwGU8EqbrFm7U0fEtPMXiOjr7x5kQBv4LXqgpCefxHmsi2yeCaKMkn6IkivnswHoMpTF6JqFzOnqQPry/4/oQmum9013iXMBBjOJNnHNhYt2r4iFepf3mYquwsD43c0o5lwa71qXNJWFHtDG35kwSxf55Me5V+mRpyDkdNdMGSXp+Ij2/6c/KuSIsOqNYlTmGI0QTxV+6ae7udfi0aciZhNX4hrc4lja+h6Vdnm31OMYiRBPFXzqPex0+bRoiFuZTfg/oYywrQSTLpN4J7HY0c8SOca/Sh1mSsKRHo6nM7yP4mrPT2biIFR3XRrAX14VByTKRI3aMe5U+URzCD3wQsne16g5TEsXLv0z3MnzaNOTYou4WSu0ZtuAljmJDCSJV07fu2SRsw228wy6hrE8KU9aZ+tVy0c/uvxjBJ6GM13bcGxdKaXvFDom48q/KPdanzT6hMpvCDq2F15lrZ7MPrxM+tqaFMu5kZxrgSaTMXEnkf+kq3WN8soz5+w5rMjLugAEDBgz4j/kJkn7I7rch8+MAAAAASUVORK5CYII=\n",
            "text/latex": "$$x^{2} + x + 1$$",
            "text/plain": [
              " 2        \n",
              "x  + x + 1"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 20
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oqTxIIzEY6FG",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 38
        },
        "outputId": "31ae5665-c291-42cc-a2a2-00fe000552d9"
      },
      "source": [
        "x*expr"
      ],
      "execution_count": 21,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIkAAAAYCAYAAADOHt4vAAAABHNCSVQICAgIfAhkiAAAA9hJREFUaIHt2V2oFVUYBuDnWJgnA6M/KrCLUkPox4iCwOBkRRBEQd3YTWN2EXSKCCIUgnNnhGUR0c9FnKAowzCQoLyoIINKSUnQoLJTUFpCv5CU5u7iWwePm9lnZu+99rZgXhj27Pne9a71rvXNmjVraNDgf4Q12I7fcRBbcMkJbVGD/xzexSqRGJdiMw7gjBPZqAb58DJ+wvyMmqfhH9ySUbNBZ1yJFu4ZhPhVOIqHMuueJxq9PLNuFc4UHbUZX+EQfsM2rMacIbenH9yBZ/CheIy38Mos/M3YL27QrNiKXzGaWfcN7MRJmXWrcK/ozB/wKtbhJeGxhU0YGXKbesUu0eY/sFd1klydOGtzNmKJmEVezCmKJ8UgXdiHRiEMj3VZboV4xLXPGOfiu6R5ex/t6gaF3jxM4zosFkk9pjpJiGT61gz/7R2xVXknjGAyxR6bcf3uFNvYocJu9WADVorB2tdBd5B4T7xZHW27fgDPp/OxknK9eB003seXqe66eB0X4MZOhMvFYnGP46f5J1JFL7Txd+CIzgvWbvWeFoOxdBYTdVHo7y4sw8NJc0NJrFuvdVDI52FMvZnkhsRbPxtpMpGK9H9t+r/R8TPPfJEguysqrav3rFhcrRBT+/TR6yKqkDdJThZeW7ipA2dSPa91URh+kixIvE9nIy0UK/pvMJ4KvIO5bbwlKba1otK6eq0Ox0SFficU8ibJ+qT39iycul7rojD8JCE8HKgirXNskD7CqSWcaxy7S3Lo9YMpnZOs7JjsUv+BVG6v6s29Xr1OVbS5Xw9j6ifJ9+IpgZhCy3Bwxvlq/FnCOZR+59WotI5eP3gKp7ddW4ZbxUbfVFtsVxfa42KttAfX4+cKfq9eB+mhW4w6Nr6luFOs7PeLzHuuA+/8FN9WUWFdvdwo9D9VP5g0duOcGvzcXgvDf9zMER6+7kS4GX/jc5yNL3AYF5dwR8RW/MGSWC96uVHor4MfSeV34qwa/EF4LQw/SZYm3ptlweViatwntsSJbd0W3uoguCnFF2XSy4lC7x38aCq7Q70PjIPyWhh+kqxKvPH2wDKx7bwfF7XFtqdC15YIrkyx+zLp5UShtw6+K5U7IvZDJkqOYgZ/kF4L/SXJbWKBOyneslriMTJ9rWwv5DXhfeHMi4vE684vuKyk0PTmysclsbn4EZ9k0suJQm8dPKH6zeKDxB2010J/STJhdh9TbfwFYsGafaZfkyq8Irdwg6HjfjGW2b+8zxMfhLbkFm4wVIyKj6qb2gM5PsMfwWc4RSz0DmfQbDB8LMZfeFyssRo0aNCgQYNh4l/pQHO+yPhywAAAAABJRU5ErkJggg==\n",
            "text/latex": "$$x \\left(x^{2} + 2 x + 1\\right)$$",
            "text/plain": [
              "  ⎛ 2          ⎞\n",
              "x⋅⎝x  + 2⋅x + 1⎠"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 21
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "viZ6yQncY-BZ",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 38
        },
        "outputId": "b95bbe83-b68b-4eb1-a14b-6df9b2e4c453"
      },
      "source": [
        "expand(x*expr)"
      ],
      "execution_count": 22,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHkAAAAWCAYAAADkWDPGAAAABHNCSVQICAgIfAhkiAAAAvNJREFUaIHt2U3IFVUcx/GPJS3CQHpDF0KkZIKa0FZBVAgLcaGLcOMRA4Uk3EQUBM8mHheWikS4KK5QiyJQkKAixEWpoKAkWAvxbdETGVkShvnyuDjnQb3e2505c8d5iPnCgXtn5vzP73f+M+ecOUNLywBex4+4ksoRvNKoovp4G8dEn5dwAPMbVfSAWI2VmIPn8B6uY2GTomriG2wQE7sA+/ArHm9SVFP8gU1Ni3gATMNNrGpayCAeGmKsh/GqaP7wEOMW4Qm8Jj5dZ/AP/sL32Gi4Pid4LMW9XEPsSccC/I0b+FMzc/JmjOMXfIZRfJL0jONLTBlym1/ghHhz/+95RJyTXxQ793d5C5IgJmRpRt1l4rDZ/cTOwMUUd01G3H58IN5Qz1aIEeT7rcS3enfIFHTSuW0DYnyHjzPaDuox/U6Ku7vreK7XHRjD8xV1Bfl+K+XpBXExcdq9w9D7qeKeAgIO4tPCcu8Q1JPkN1PcHV3Hc7zuElfU84agK8j3WzlPnXRhSP8nnoTP3T8cbsMSPCPOzaO4Jb5WlSUYfpKn4lSK+1KP8x3FvX4oviMvE6eBiTItU1tQzW9Hce33MUtcnZ7DllTxa3Hu7dXQBVzDb+JQ3aszixAMP8nbU8yv+pwv43W8TxnJ1BZU81tGe09G3THxAx7NFNKP8/p3Wq/SyWjjjVT3J/+9YVG3V+rzW0j71D6VL931eyOuFmy0KDsxvevYInEHba/YKXdzsmT8LeL8eRrLxQ2aftTtlfr8ZmtfJ86rY+Id8lHRihUJhjNcb01xTuHpAdc25ZXqfrO1v4x/xY8OT+FncS96bqaQMgTVk/xWinECTw64tkmvVPObrX2x+Lifxcx0bG0Ssj9DSFmCakl+N9U/bvBHg6a9ku83W/sicQtwDLO7zh1LAZaUFFOWID/J61PdG+L78EiPEtK1k8EreX6ztc8RX/Av6/2JcEWqfLSEmByC/CSPGLxiPWTyeKW838mkvaWlpaWlpSWD2xzPI/UQvut2AAAAAElFTkSuQmCC\n",
            "text/latex": "$$x^{3} + 2 x^{2} + x$$",
            "text/plain": [
              " 3      2    \n",
              "x  + 2⋅x  + x"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 22
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "PBhPf6JfZhfY",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 38
        },
        "outputId": "47c5e295-14fb-4cfd-8453-19d0d0af472c"
      },
      "source": [
        "eq = Eq(x**2 - 4 , 0)\n",
        "\n",
        "eq"
      ],
      "execution_count": 25,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGMAAAAWCAYAAADU1CLnAAAABHNCSVQICAgIfAhkiAAAAtJJREFUaIHt2E2oVVUUwPHfs4cg+jAVwsCH4Ss/wEqdiFBNFAeBEOlICgudBIrRKAXhIoiCaYkIqeBH0UAnBk3yc1Kk4MCaiJ/5StCigZqaJpQO1r695+2cd999nvuOT+8fNpu79tprrXvW2Xvts2nxxLAKJ/En/sA3mF5qRE8xB/G+SMDLOIDfMLbMoFoEo/APFpQdyFBkWMH2OpLNawXbHQjv4H5qy0qMYwJ24Qr+Rjc+w5hmO96PU3im2Y7q0InruKncZHTh9xTD19iAY+n3GYxrluPNIvuTmuWgn7ThCC5io3KTcTD5X1Ej35zkn/c1+VBSWlgjb8OeNLYhY96nuIqpDYdbPCvxL95ARXnJ6Eq+L/l/OejALdzGyDwDr4oCfNrDW82mZHh7xpwt4gQ1baBRF8g03BEvB+UmY5n8Z0bPqplbFbTXKPyEL7EE74rVsBofiXrwQY3+tqT3lija45P8VmqDSbuI/VcRc6N8iGcb0P9R1IE8pqT+XM74eczHZBzNM9Ip3q5LWC6y9y2GZ+jez2mVPoJsFmvFqp7TS1bR/5XRLf//ZLU9deztqON7XRpfVRXUrgy4LI5eH2MrfsDbuJeh21YnoDy6MbEB/a/EUTWP2WI1bMLxAcb0wgDnFUZWMoirjSpL8VfBfi/ibgP6V/oYa8cXYjtY8yhBFcyN1I/OGa/Kr1cFWclYjE9EUR4vTie1teJRmVtfpd+MEvsu+QnemdoWURuyKLpmnE395Jzxl1L/X02p3WbeTA7OiAf2nTiiTe9l/HFjhNhOs5iFmfhexH8Y+3J0uzW2de7Fe32Md+FCstsljttVOsSnQBueE0fch3hNbEc/4/kkW6Tn63EoUjEEP/pmiL3rqshib06mia8XGubgUPF4XYes13MdclbGdciLoj5cwysZBuelySeaE29TqSj/orATu8WLfg+/GKSLwhYtWrRo8eTyALX6uY5V8N6oAAAAAElFTkSuQmCC\n",
            "text/latex": "$$x^{2} - 4 = 0$$",
            "text/plain": [
              " 2        \n",
              "x  - 4 = 0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 25
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "byhXQWlXZ5g8",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 37
        },
        "outputId": "ea7f5081-4d01-46e1-ce09-1ee0d98e3ea0"
      },
      "source": [
        "solveset(eq)"
      ],
      "execution_count": 26,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAE4AAAAWCAYAAABud6qHAAAABHNCSVQICAgIfAhkiAAAAmBJREFUWIXt2E2IjVEYB/DfmJGUmBBTUpSUr7KQpSZRSpM0OwsURdGwYyOiiWTK0mqymNlIIdRsiEyRjyiJhcUkaTbKpIwajMU5t3ubud55z517594y/3o7b/c8///znI/7nOc9zKIm2IdnGMFvbK5vODOCcxjDMG5jbarAevzBd/TiAtqqFx9YgsO4hY8YFRZpEIcwpw7a7biEAYzjearjY5HYlUpMwNHo4wv6cVFYpG/x95toqqP2K2HzLEhxfCY62JkWbxK2o8Pk1W/Dp+i/s47a/dFu5cSOrL9Cc2zHcoVZGR7irrCqpRjGtfjeXkftwtibJ3ZMJ4fUGoWgfzWidtbEtcZ2tFLxaaAF++P7QB21f8Z2UV7xJsXEWO2TNA+uCLnlfp21T0fbE1MZ7kIPXkTCtWxzQ9Eu79OXI9iuaPsei3PYpyBVe4UwxjHcQDdWlTO8qjjIt9gwhfADfEh4Lk+hdzz6fqf6O71S7SP4oTgv7f8yXIg9Qm77rMyJUiOcVFywZQ2ivTvyBoVNNDcPqS+SNqbFWBFORV+vsbSBtHsid0cKqTuStiU6S0Wh0H4pf067HjkHa6Bdit7IXzOxoyWDVKh1alnrHcB54QLhifKfd0PCRJWiEFNWHVapdi4/WRM3ntFXLayObbOQh8rhscmD2yRcPmSVFJVql0PSXBRqmL0ppBlAq7CLpjqhq4E7whwsTyF1RtI94SO3UT7POoSKvpaF+TxsFa6hRiSOfb5wfJcWsP/LRWbpmM+WM8rKcaPYIlzPrBPupIarGmJj4pFwGHzFU7ypazSzmAX4Cytzw5dCFkJJAAAAAElFTkSuQmCC\n",
            "text/latex": "$$\\left\\{-2, 2\\right\\}$$",
            "text/plain": [
              "{-2, 2}"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 26
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "hFGhLkWqaOcM",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 41
        },
        "outputId": "20f63847-f945-438f-83f0-b5485317a4da"
      },
      "source": [
        "Integral(1/sqrt(x) , x)"
      ],
      "execution_count": 28,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEQAAAAkCAYAAAAw55zoAAAABHNCSVQICAgIfAhkiAAAA45JREFUaIHt2V2MXVMUB/Df6JBiKiJUhLZRxIuYcUWJ+CiRERUSUQ/6UMIraSSS0oR4IJU2HkgQkcgwPPShwjQaPEhofNZXmqa8IPVVlPgaLR3Uw9o3986Z+3Xu3DN3Ou4/OTnn7LXW3v+z79p7rbUvPbSNPszrNonZgPlYj58xjg3+5xMzioOZa11XGXURC/GvmITbcUN6/qoF20swhm+Szc3FUOws+pvIh8TeAc/hV2zFXhyFfQ1sB7ATz6RrTmCV+HX3T7OfcYeIhxzWRL4g3X8rmshsQbMJGUj38aKJdBCLhFc/345xqx7yezuddwnnpvuH7RjPRQ8ppfsH7Rj3PCSDIj1kQITtoTTO4vS8uI2+sujHGuzAn9iNtSJFKOFbfJ90XxV7yvWZPvowkmQPtjrwWDJ4qg3Sy03NcA8mEtPBESof+RE2Jn778WRqH6vSH8Q/2GVyyfFQ0n0iz+CvJaNH2uNeCMoffY9K0khkxuVJvy9jM2JytrwuvW/SfJVMwvZk+EAuysVhmeCzpY58V5Jfk2lfJDzoC9yWdF4W3pYLnyTju/MaFoRyoXlBHfm2JD+5hmy9ige9KUqPKTjUoswwfsK7deRL8YMoKLPYW/V8q8Z1WF38onGlWmvT7NSVxfzUXi+clpJ8aw3ZKlG170k6j9fpoyn+VjtkdQOHCz5f15FvFlzvz7SvwAERok/Ap5jAmXkJHKnya12Z17gglPe07Ka5VoXrdVXtF4ml8TlOSm0rk94LeQdfWDXIhXmNcQte1LklA6uT7IA4Y9mA90QE+TLJliTdIbHk9+C0TD/l6Hlxng9aWkXu7DyGCdu0EdZawBrxi0+IbHSz2D9248ekczq+E+fAtbhfIb7rnTwDD6pMyKk5SZfwaE6bWYFGYXdB1XPesLsaT9doX4m/VNwaHsZnODHnGIVjmQhZj6X3G4V3TMiX3vbj9TqyPrwv0m+4U+QNZ+QlOxMo7xn7cA5eSu/bG9icL+qBe6vaVmic2Q6LSb5LHE2e1z7l4rHF1N2+UQ5yPG4SG1r16fwpTcZ5S+QUV02H7EzgWDwr/m74GNe2YHO0OC+5FMeYXHrXwuX4Q5TkpSa6M46+5iotYVQc1LwtlsNoHb1BvIE7cLU4RJotSV9HMSxi/ivCY2phiTjJKu83Z4n6YnnR5LqBeeJjR+rIjxNpd/Z0apPwqjmJjbis2yR66KGHGcV/34kDzu6UlXgAAAAASUVORK5CYII=\n",
            "text/latex": "$$\\int \\frac{1}{\\sqrt{x}}\\, dx$$",
            "text/plain": [
              "⌠      \n",
              "⎮ 1    \n",
              "⎮ ── dx\n",
              "⎮ √x   \n",
              "⌡      "
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 28
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "1ZCssMIlacMo",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "init_printing(use_latex='mathjax')"
      ],
      "execution_count": 29,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "NYAFZDoZbFnD",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 41
        },
        "outputId": "e06be617-812b-454f-ff38-c03d237ec9f3"
      },
      "source": [
        "Integral(1/sqrt(x) , x)"
      ],
      "execution_count": 34,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/latex": "$$\\int \\frac{1}{\\sqrt{x}}\\, dx$$",
            "text/plain": [
              "⌠      \n",
              "⎮ 1    \n",
              "⎮ ── dx\n",
              "⎮ √x   \n",
              "⌡      "
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 34
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "BVqAs6AOcAFL",
        "colab_type": "text"
      },
      "source": [
        "$ \\int \\sqrt{\\frac{1}{x}}\\, dx $"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GPD8pQhYbHy8",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "str_expr = \"x**2 + 3*x - 1/2\"\n",
        "\n",
        "exp2 = simplify(str_expr)"
      ],
      "execution_count": 35,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "LHiHvxK4dGmS",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 38
        },
        "outputId": "b6682e2d-f714-4cae-b165-b32155bdeaea"
      },
      "source": [
        "exp2"
      ],
      "execution_count": 36,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/latex": "$$x^{2} + 3 x - \\frac{1}{2}$$",
            "text/plain": [
              " 2         1\n",
              "x  + 3⋅x - ─\n",
              "           2"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 36
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ar34xipKdHyy",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 38
        },
        "outputId": "97bc1883-f4eb-454b-e9cb-f13cc4faae85"
      },
      "source": [
        "#substituting x = 2 in a expression and finding f(2)\n",
        "\n",
        "exp2.subs(x,0)"
      ],
      "execution_count": 38,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/latex": "$$- \\frac{1}{2}$$",
            "text/plain": [
              "-1/2"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 38
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "uHWbxdZBdwHT",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 37
        },
        "outputId": "aff931e1-d9aa-464a-d8e3-144341c11a2c"
      },
      "source": [
        "exp3 = 2*sqrt(2)\n",
        "\n",
        "exp3.evalf()"
      ],
      "execution_count": 40,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/latex": "$$2.82842712474619$$",
            "text/plain": [
              "2.82842712474619"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 40
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "3pTESCoffmEB",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 37
        },
        "outputId": "18e60e37-36f5-4d48-9ecc-4907368e66af"
      },
      "source": [
        "pi.evalf(40)"
      ],
      "execution_count": 41,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/latex": "$$3.141592653589793238462643383279502884197$$",
            "text/plain": [
              "3.141592653589793238462643383279502884197"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 41
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "b5Q7s73Afyxe",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 37
        },
        "outputId": "a25f762f-3b4e-4a23-9ec1-f881f22651c9"
      },
      "source": [
        "cos(2*x).subs(x,pi)"
      ],
      "execution_count": 42,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/latex": "$$1$$",
            "text/plain": [
              "1"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 42
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "4YfGgPt6f7m2",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "f , g = symbols('f g')"
      ],
      "execution_count": 46,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "BdivEyeAgcJX",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 38
        },
        "outputId": "0a1003af-4459-43b2-ca7e-e23fbeceda00"
      },
      "source": [
        "f(x)"
      ],
      "execution_count": 47,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/latex": "$$f{\\left (x \\right )}$$",
            "text/plain": [
              "f(x)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 47
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "y-ZF19NNgq1A",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 38
        },
        "outputId": "f28a6398-4bbd-4561-b43d-5ca7625985b3"
      },
      "source": [
        "f(x).diff()"
      ],
      "execution_count": 48,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/latex": "$$\\frac{d}{d x} f{\\left (x \\right )}$$",
            "text/plain": [
              "d       \n",
              "──(f(x))\n",
              "dx      "
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 48
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "IXEhilUAgujr",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 40
        },
        "outputId": "8c6e2f79-bb10-4dcf-c741-a544196f3549"
      },
      "source": [
        "f(x).diff().diff()"
      ],
      "execution_count": 49,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/latex": "$$\\frac{d^{2}}{d x^{2}}  f{\\left (x \\right )}$$",
            "text/plain": [
              "  2      \n",
              " d       \n",
              "───(f(x))\n",
              "  2      \n",
              "dx       "
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 49
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "zloeIAigg2S4",
        "colab_type": "text"
      },
      "source": [
        "#SOlving an ODE"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "DZw8JyEpgyS2",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "diffeq = Eq(f(x) - 2*f(x).diff(x) + f(x).diff(x,x) , sin(x))"
      ],
      "execution_count": 50,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "1k05s4Obhwuh",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 40
        },
        "outputId": "ae17f692-ec23-4a69-87ab-b52e367961f0"
      },
      "source": [
        "diffeq"
      ],
      "execution_count": 51,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/latex": "$$f{\\left (x \\right )} - 2 \\frac{d}{d x} f{\\left (x \\right )} + \\frac{d^{2}}{d x^{2}}  f{\\left (x \\right )} = \\sin{\\left (x \\right )}$$",
            "text/plain": [
              "                      2               \n",
              "         d           d                \n",
              "f(x) - 2⋅──(f(x)) + ───(f(x)) = sin(x)\n",
              "         dx           2               \n",
              "                    dx                "
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 51
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "dtWcDpuihyEg",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 38
        },
        "outputId": "3e6654cc-4f7c-46fd-d283-a21a8ea0e4b8"
      },
      "source": [
        "dsolve(diffeq)"
      ],
      "execution_count": 52,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/latex": "$$f{\\left (x \\right )} = \\left(C_{1} + C_{2} x\\right) e^{x} + \\frac{1}{2} \\cos{\\left (x \\right )}$$",
            "text/plain": [
              "                    x   cos(x)\n",
              "f(x) = (C₁ + C₂⋅x)⋅ℯ  + ──────\n",
              "                          2   "
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 52
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "aDAVo9sziMPf",
        "colab_type": "text"
      },
      "source": [
        "#Finite Differences"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-qH0SUlfiD4R",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "dfdx = f(x).diff(x)\n",
        "\n",
        "h = symbols('h')"
      ],
      "execution_count": 58,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "T2PoNSfGihAw",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 38
        },
        "outputId": "cd607b6d-53e7-4fb7-a4e2-edd28525fbbc"
      },
      "source": [
        "dfdx.as_finite_difference(h)"
      ],
      "execution_count": 59,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/latex": "$$- \\frac{1}{h} f{\\left (- \\frac{h}{2} + x \\right )} + \\frac{1}{h} f{\\left (\\frac{h}{2} + x \\right )}$$",
            "text/plain": [
              "   ⎛  h    ⎞    ⎛h    ⎞\n",
              "  f⎜- ─ + x⎟   f⎜─ + x⎟\n",
              "   ⎝  2    ⎠    ⎝2    ⎠\n",
              "- ────────── + ────────\n",
              "      h           h    "
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 59
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MrosKb7YiqD0",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 38
        },
        "outputId": "5e8edae1-2820-4f93-e5c8-3998af68a324"
      },
      "source": [
        "dfdx_2 = f(x).diff(x,x)\n",
        "\n",
        "dfdx_2.as_finite_difference(h)"
      ],
      "execution_count": 60,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/latex": "$$- \\frac{2}{h^{2}} f{\\left (x \\right )} + \\frac{1}{h^{2}} f{\\left (- h + x \\right )} + \\frac{1}{h^{2}} f{\\left (h + x \\right )}$$",
            "text/plain": [
              "  2⋅f(x)   f(-h + x)   f(h + x)\n",
              "- ────── + ───────── + ────────\n",
              "     2          2          2   \n",
              "    h          h          h    "
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 60
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "LO0JovAQjlOm",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#Devito is an enhanced version of SymPy's Finite Differences Method. "
      ],
      "execution_count": 61,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oppSvBNkj6YN",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    }
  ]
}